﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using System.Windows.Input;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using phoneapp.Resources;

namespace phoneapp
{
    public class Helper
    {
        
        private List<string>[] hContent;

        Helper()
        {
            hContent = new List<string>[2];
            hContent[0].Add("Header");
            hContent[1].Add("Content");
        }

        public List<string>[] getList()
        {
            return hContent;
        }

        
    }
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        Point prevPosition;
        int prevTime;
        private string buildVersion = "Build version: 1.2.0.1";
        public MainPage()
        {
            InitializeComponent();
            GoStartCalc.Click += new RoutedEventHandler(StartCalc);
            
            StringBuilder sb = new StringBuilder();
            sb.Append("Position: none\nAction: none\nTouchDeviceId: none\nDirectlyOver: none\nSize: none\nPosition: none\n");
            TextBlock1.Text = sb.ToString();
            TextBlock1.Text += buildVersion;
            Touch.FrameReported += new TouchFrameEventHandler(Touch_FrameReported);
            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }
        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            var primaryPoint = e.GetPrimaryTouchPoint(null);
 

            if (primaryPoint != null)
            {

                /* if (primaryPoint.Action == TouchAction.Down)
                 {
                      prevPosition = primaryPoint.Position;
                      prevTime = GetEpochTime();
                     
                 }
                     sb.Append("TimeRelative: " + GetEpochTime() + "\n");
                 if (primaryPoint.Action == TouchAction.Up)
                 {

                     if ((prevPosition.X - primaryPoint.Position.X) > 15f && ((GetEpochTime() - prevTime) < 2) && Math.Abs(prevPosition.Y - primaryPoint.Position.Y) < 70f)
                         NavigationService.Navigate(new Uri("/help.xaml", UriKind.Relative));

                     if ((primaryPoint.Position.X - prevPosition.X ) > 15f && ((GetEpochTime() - prevTime) < 2) && Math.Abs(prevPosition.Y - primaryPoint.Position.Y) < 70f)
                     {
                         if (NavigationService.CanGoBack)
                             NavigationService.GoBack();
                     }
                 }*/

                sb.Append("Position: X-" + primaryPoint.Position.X.ToString() + " Y-" + primaryPoint.Position.Y.ToString() +

        "\n");
                sb.Append("Action: " + primaryPoint.Action.ToString() + "\n");
                sb.Append("TouchDeviceId: " + primaryPoint.TouchDevice.Id.ToString() + "\n");
                sb.Append("DirectlyOver: " + (primaryPoint.TouchDevice.DirectlyOver as FrameworkElement).Name + "\n");
                sb.Append("Size: Width-" + primaryPoint.Size.Width.ToString() + " Height-" + primaryPoint.Size.Height.ToString

        () + "\n");
            }
            var points = e.GetTouchPoints(null);
            if (points != null)
            {
                foreach (var point in points)
                {
                    sb.Append("Position: X-" + point.Position.X.ToString() + " Y-" + point.Position.Y.ToString() + " " +

                    point.Action.ToString() + "\n");
                }
            }
            TextBlock1.Text = sb.ToString();
            TextBlock1.Text += buildVersion;
        }

        public int GetEpochTime()
        {
            DateTime dtCurTime = DateTime.Now;
            DateTime dtEpochStartTime = Convert.ToDateTime("1/1/1970 8:00:00 AM");
            TimeSpan ts = dtCurTime.Subtract(dtEpochStartTime);
            int epochtime;
            epochtime = ((((((ts.Days * 24) + ts.Hours) * 60) + ts.Minutes) * 60) + ts.Seconds);
            return epochtime;
        }

        private void StartCalc(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/CalcPage.xaml", UriKind.Relative));
        }

        private void Pivot_Loaded_1(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            // ContentPanel.Children.Add(myButton);
            if (int.Parse((HelpButton1.Tag.ToString())) == 1)
            {
                Help1.Height = 160;
                HelpButton1.Tag = 0;
            }
            else
            {
                Help1.Height = 0;
                HelpButton1.Tag = 1;
            }
        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            // ContentPanel.Children.Add(myButton);
            if (int.Parse((HelpButton3.Tag.ToString())) == 1)
            {
                Help3.Height = 160;
                HelpButton3.Tag = 0;
            }
            else
            {
                Help3.Height = 0;
                HelpButton3.Tag = 1;
            }
        }

        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            // ContentPanel.Children.Add(myButton);
            if (int.Parse((HelpButton4.Tag.ToString())) == 1)
            {
                Help4.Height = 160;
                HelpButton4.Tag = 0;
            }
            else
            {
                Help4.Height = 0;
                HelpButton4.Tag = 1;
            }
        }
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            Button myButton = new Button();
            myButton.Height = 190;
            myButton.Width = 340;
            myButton.Content = "Click me";
           // ContentPanel.Children.Add(myButton);
            if (int.Parse((HelpButton2.Tag.ToString())) == 1)
            {
                Help2.Height = 160;
                HelpButton2.Tag = 0;
            }
            else
            {
                Help2.Height = 0;
                HelpButton2.Tag = 1;
            }
        }

        // Sample code for building a localized ApplicationBar
        //private void BuildLocalizedApplicationBar()
        //{
        //    // Set the page's ApplicationBar to a new instance of ApplicationBar.
        //    ApplicationBar = new ApplicationBar();

        //    // Create a new button and set the text value to the localized string from AppResources.
        //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
        //    appBarButton.Text = AppResources.AppBarButtonText;
        //    ApplicationBar.Buttons.Add(appBarButton);

        //    // Create a new menu item with the localized string from AppResources.
        //    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
        //    ApplicationBar.MenuItems.Add(appBarMenuItem);
        //}
    }
}